package itheima;

public class TestLambda {
    public static void main(String[] args) {
        //testA();
        //testB();
        //testC();
        testD();
    }



    public static void testA() {
        // 1. 匿名内部类
        A a1 = new A() {
            @Override
            public void show(String name, int age) {
                System.out.println(name + "," + age);
            }
        };
        a1.show("李四",18);

        A a2 = (name,age) -> System.out.println(name + "," + age);
        a2.show("张三",20);


        A a3 = TestLambda::show2;
        a3.show("李四",25);
    }

    public static void testB(){
        B b1 = new B() {
            @Override
            public void show(String name) {
                System.out.println(name);
            }
        };
        b1.show("Ciallo～(∠・ω< )⌒☆");

        B b2 = name -> System.out.println(name);
        b2.show("Ciallo～(∠・ω< )⌒☆");

        B b3 = System.out::println;

    }

    public static void testC() {
        // 2. 创建内部类对象
        C c1 = new C() {
            @Override
            public String show(String name) {
                return "name: " + name;
            }
        };
        //lambda表达式
        C c2 = (name) -> "name: " + name;

        //创建方法引用
        C c3 = TestLambda::show3;
        //调用方法
        String s = c3.show("张三");
        System.out.println(s);
    }

    public static void testD(){
        D d1 = new D() {
            @Override
            public int max(int a, int b) {
                return a > b ? a : b;
            }
        };
        D d2 = (a,b) -> a > b ? a : b;
        D d3 = Math::max;
        int max = d3.max(10,20);
        System.out.println(max);

    }




    public static void show2(String s, int i) {
        System.out.println(s + "," + i);
    }
    public static String show3(String name) {
        return "name: " + name;
    }
}

